//
//  WBHomeViewController.swift
//  微博
//
//  Created by ddchina on 2017/9/22.
//  Copyright © 2017年 haqiuhehe. All rights reserved.
//

import UIKit
//定义全局常量，尽量使用private修饰，否则到处都可以访问
private let cellId = "cellId"
class WBHomeViewController: WBBaseViewController {

    fileprivate lazy var statusList = [String]()

    // 加载数据
    override func loadData() {
        
        for i in 0..<10 {
            // 将数据插入到数组的顶部
            statusList.insert(i.description, at: 0)
        }
    }
    /// 显示好友
    @objc fileprivate func showFriends() {
        print(#function)
        
        let vc = WBDemoViewController()
//        vc.hidesBottomBarWhenPushed = true
        // push的动作是 nav 做的
        navigationController?.pushViewController(vc, animated: true)
    }
}

// MARK: - 表格数据源方法,具体的数据源方法实现，不需要super
extension WBHomeViewController {
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return statusList.count
    }
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        //1. 取 cell
        let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath)
        //2. 设置 cell
        cell.textLabel?.text = statusList[indexPath.row]
        //3. 返回 cell
        return cell
    }
}
// MARK: - 设置界面
extension WBHomeViewController {
    
    /// 重写父类方法
    override func setupUI() {
        super.setupUI()
        
        //设置导航栏按钮
        navItem.leftBarButtonItem = UIBarButtonItem(title: "好友", target: self, action: #selector(showFriends))
        
        // 注册
        tableView?.register(UITableViewCell.self, forCellReuseIdentifier: cellId)
    }
}
